from django.db import models


class MediumList(models.Model):
    """ 媒介表 """
    created_at = models.DateField('日期')
    platform = models.CharField('平台', max_length=20)
    amount = models.DecimalField('金额', max_digits=64, decimal_places=2)
    rebate = models.FloatField('返点', max_length=10)
    recharge = models.DecimalField('账户币', max_digits=64, decimal_places=2,
                                   help_text='<span style="color:red">不写自动带公式填充</span>')
    remark = models.TextField('备注', max_length=256, null=True, blank=True)

    def clean(self):
        super().clean()
        if self.recharge is None:
            self.recharge = float(self.amount) * (1 + self.rebate / 100)

    def __str__(self):
        return self.platform

    class Meta:
        db_table = 'medium_list'
        verbose_name = '媒介'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']
